<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="utf-8">
  <title>Comments &laquo; Admin</title>
  <link rel="stylesheet" href="../static/assets/vendors/bootstrap/css/bootstrap.css">
  <link rel="stylesheet" href="../static/assets/vendors/font-awesome/css/font-awesome.css">
  <link rel="stylesheet" href="../static/assets/vendors/nprogress/nprogress.css">
  <link rel="stylesheet" href="../static/assets/css/admin.css">
  <script src="../static/assets/vendors/nprogress/nprogress.js"></script>
</head>
<body>
  <script>NProgress.start()</script>

  <div class="main">
    <!-- 引入公共的顶部 -->
    <?php include "public/_navBar.php"?>
    <div class="container-fluid">
      <div class="page-title">
        <h1>所有评论</h1>
      </div>
      <!-- 有错误信息时展示 -->
      <!-- <div class="alert alert-danger">
        <strong>错误！</strong>发生XXX错误
      </div> -->
      <div class="page-action">
        <!-- show when multiple checked -->
        <div class="btn-batch" style="display: none">
          <button class="btn btn-info btn-sm">批量批准</button>
          <button class="btn btn-warning btn-sm">批量拒绝</button>
          <button class="btn btn-danger btn-sm">批量删除</button>
        </div>
        <ul class="pagination pagination-sm pull-right">
          <li><a href="#">上一页</a></li>
          <li><a href="#">1</a></li>
          <li><a href="#">2</a></li>
          <li><a href="#">3</a></li>
          <li><a href="#">下一页</a></li>
        </ul>
      </div>
      <table class="table table-striped table-bordered table-hover">
        <thead>
          <tr>
            <th class="text-center" width="40"><input type="checkbox"></th>
            <th>作者</th>
            <th>评论</th>
            <th>评论在</th>
            <th>提交于</th>
            <th>状态</th>
            <th class="text-center" width="100">操作</th>
          </tr>
        </thead>
        <tbody>
          
        </tbody>
      </table>
    </div>
  </div>

  <!-- 引入公共的侧边栏 -->
  <?php 
    $currentPage = 'comments';
    $currentPage1 = 'comments';
   ?>
  <?php include "public/_aside.php"?>

  <script src="../static/assets/vendors/jquery/jquery.min.js"></script>
  <script src="../static/assets/vendors/bootstrap/js/bootstrap.js"></script>
  <script src="../static/assets/vendors/twbs-pagination/jquery.twbsPagination.min.js"></script>
  <script>NProgress.done()</script>
</body>
<script>
    $(function(){
        //获取当前是第几页
        var currentPage = 1;
        //获取一页有多少条
        var pageSize = 10;
        //可以分多少页
        var pageNum;
        getCommentsData();
        //封装页面一打开就加载页面数据
        function getCommentsData(){
            $.ajax({
              type:"post",
              url:"api/_getComments.php",
              data:{
                  "currentPage":currentPage,
                  "pageSize":pageSize
              },
              success:function(res){
                  if(res.code == 1){
                      var data = res.data;
                      pageNum = res.pageNum;
                      var str = "";
                      $.each(data,function(index,val){
                          str +=`<tr>
                                  <td class="text-center"><input type="checkbox"></td>
                                  <td>${val.author}</td>
                                  <td>${val.content}</td>
                                  <td>${val.title}</td>
                                  <td>${val.created}</td>
                                  <td>${val.status=="held"?"未批准":"已批准"}</td>
                                  <td class="text-center">
                                    <a href="post-add.php" class="btn ${val.status == "held"?"btn-success":"btn-info"} btn-xs">${val.status == "held"?"批准":"驳回"}</a>
                                    <a href="javascript:;" class="btn btn-danger btn-xs">删除</a>
                                  </td>
                                </tr>`;
                      });
                      $("tbody").html(str);
                      //分页的实现
                      $('.pagination').twbsPagination({
                          totalPages:pageNum,//总共有多少页
                          visiblePages:5,//可以显示几个按钮
                          first:"首页",
                          last:"末页",
                          prev:"上一页",
                          next:"下一页",
                          onPageClick:function(event,page){//page 获取当前页码
                              currentPage = page;
                              getCommentsData();
                          }

                      });
                      
                  }
              }

            });
        }

        
    });
</script>
</html>
